package com.lyl.yygh.service.hosp.service.impl;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyl.yygh.common.service_util.result.Result;
import com.lyl.yygh.model.hosp.HospitalSet;
import com.lyl.yygh.model.vo.HospitalSetQueryVo;
import com.lyl.yygh.service.hosp.dao.HospitalSetDao;
import com.lyl.yygh.service.hosp.service.HospitalSetService;
import org.springframework.stereotype.Service;

/**
 * @author 罗亚龙
 * @date 2022/1/4 14:18
 */
@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetDao, HospitalSet> implements HospitalSetService {

    @Override
    public Result findPageHospSet(long current, long limit, HospitalSetQueryVo queryVo) {
        Page<HospitalSet> page = new Page<>(current, limit);
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
        wrapper.like(StrUtil.isNotBlank(queryVo.getHosName()), "hosname", queryVo.getHosName())
                .eq(StrUtil.isNotBlank(queryVo.getHosCode()), "hoscode", queryVo.getHosCode());

        Page<HospitalSet> hospitalSetPage = this.page(page, wrapper);
        return Result.ok(hospitalSetPage);
    }

    @Override
    public Result saveHospSet(HospitalSet set) {
        //设置可用状态  1：可用  0：不可使用
        set.setStatus(1);
        set.setSignKey(SecureUtil.md5(String.valueOf(System.currentTimeMillis() + RandomUtil.randomInt(1000))));
        return this.save(set) ? Result.ok() : Result.fail();
    }
}
